var spawn=require('child_process').spawn;

var child=spawn('node',['plus']);

var timer=setInterval(function () {
    var n=Math.random()*10|0;
    child.stdin.write(n+'');
    child.stdout.once('data', function (data) {
        console.log('input number:',n);
        console.log('child out:'+data);
    });
},500);

child.stderr.on('data', function (err) {
    process.stdout.write(err);
});

child.on('exit', function (code) {
    clearInterval(timer);
    console.log('child process exit with code:'+code);
});